A Python base application needs to be able to communicate
with MySQL database and perform database operations. This means that
you need to create a connection between
Python and MySQL. For example, Little Lemon needs to create a connection
between their website, which relies on Python, and then MySQL database so that customers can view data like
menus and booking slots. Let's take a few
minutes to find out how a connection is established between
Python, and MySQL. At this stage, you
may be familiar with MySQL Connector python
API software package. This API facilitates
the connection between Python and MySQL, but first, you need to import it into the
Python program. To import the
Connector API type, import followed by the
mysql.connector then select run. However, typing the MySQL.connector each time you need to work
with API can be tedious. Let's create an ADS. You can feed any of
these from MySQL dot connector called connector. You can then make use of this shorthand to make
your code more efficient. To create an ADS you can type, import MySQL dock
connector again, or use existing code. But this time include connector. The as keyword instructs
Python to recognize important MySQL
dot connector used in connected areas
in all future code. Now each time you need to use
MySQL Connector Python API, you just type its alias, which is the connector,
will make sure you have installed the
Connector API first, otherwise you got a
module not found error. You've now successfully
imported the connector API, also called a
package of software. Now you can begin to make
use of its module is a functionality using the
axis operator, or the dot. For example can help Little Lemon to make use of a connector to establish
connection between their Python-based website, and the MySQL database. First, create a variable to access a connector from
the connector module, call it connection,
and assign it the value of connector.connect. Next, pass the
keyword arguments to the connect module within
the pair of parenthesis. These arguments are the database, username and password, only an authorized user
can access that activate. In this instance,
the user is Mario, and the password is cuisine. By default, a connection
is established when Python and the database installed
locally on your machine. This database is called
local host also access through its
IP of one T7.0.0.1. More about logos
and other arguments at a later stage of this course. For now, you should be able to create a connection
between Python and MySQL. Nice work.